package com.hisan.freeride.home.adapter;

import android.net.Uri;
import android.view.View;

import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.view.SimpleDraweeView;
import com.github.library.BaseQuickAdapter;
import com.github.library.BaseViewHolder;
import com.hisan.freeride.R;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.home.model.OfferMessage;


import java.util.List;

/**
 * 优惠消息适配器
 * Created by yu on 2017/1/17.
 */

public class OfferMesageAdapter extends BaseQuickAdapter<OfferMessage,BaseViewHolder> {
    private onItemClickListener mOnItemClickListener;
    public OfferMesageAdapter(List<OfferMessage> data) {
        super(R.layout.offermessage_item,data);
    }

    @Override
    protected void convert(BaseViewHolder holder, OfferMessage homeModel) {
        holder.setText(R.id.data, homeModel.getCreate_time());
        holder.getView(R.id.more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener != null){
                    mOnItemClickListener.onItemClick(homeModel);
                }
            }
        });
        SimpleDraweeView simpleDraweeView=holder.getView(R.id.logo);
        if (!CollectionUtils.isNullOrEmpty(homeModel.getThumbnail())){
            RoundingParams roundingParams = RoundingParams.fromCornersRadius(5f);
            Uri uri = Uri.parse(homeModel.getThumbnail());
            simpleDraweeView.setImageURI(uri);
            simpleDraweeView.getHierarchy().setRoundingParams(roundingParams);
        }else{
            simpleDraweeView.setImageResource(R.mipmap.mall);
        }
        holder.setText(R.id.name, homeModel.getTitle());
        holder.setText(R.id.news, homeModel.getDescription());
    }
    public void setOnItemClickListener(onItemClickListener listener) {
        mOnItemClickListener = listener;
    }
    /**
     * 自定义的recyclerView点击监听
     */
    public interface onItemClickListener {
        void onItemClick(OfferMessage data);
    }
}
